﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using SCMS.UI.Validators.Date;

namespace SCMS.UI.Models
{

    public class ChoosePOType
    {
        [Display(Name = "Single Quote")]
        public bool IsSingleQuote { get; set; }

    }

    public class POModel
    {
        public Model.PurchaseOrder POEntiy { get; set; }

        [Required(ErrorMessage = "Required Field")]
        public Guid TAID { get; set; }
        public SelectList TAnalysis { get; set; }

        [Required]
        public string PONumber { get { return POEntiy.RefNumber; } set { POEntiy.RefNumber = value; } }

        [Required(ErrorMessage = "Required Field")]
        public Guid? ORID { get { return POEntiy.OrderRequestId; } set { POEntiy.OrderRequestId = value; } }
        public SelectList OrderRequests { get; set; }

        public string DRCRemarks { get { return POEntiy.Remarks; } set { POEntiy.Remarks = value; } }

        [Required(ErrorMessage = "Required Field")]
        public Guid paymentTerm { get; set; }
        public SelectList PaymentTerms { get; set; }

        [Required(ErrorMessage = "Required Field")]
        public Guid shippingTerm { get; set; }
        public SelectList ShippingTerms { get; set; }

        [Required(ErrorMessage = "Required Field")]
        public Guid supplierID { get { return (Guid)POEntiy.SupplierId; } set { POEntiy.SupplierId = value; } }
        public SelectList suppliers { get; set; }

        [Required(ErrorMessage = "Required Field")]
        public DateTime deliveryDate { get { return (DateTime)POEntiy.LatestDeliveryDate; } set { POEntiy.LatestDeliveryDate = value; } }

        [Required(ErrorMessage = "Required Field")]
        public Guid deliveryAddressID { get { return POEntiy.DeliveryAddress; } set { POEntiy.DeliveryAddress = value; } }
        public SelectList deliveryAddress { get; set; }

        [Required]
        public string QuatationRef { get { return POEntiy.QuotationRef; } set { POEntiy.QuotationRef = value; } }

        [Required(ErrorMessage = "Required Field")]
        [DateRange(ErrorMessage = "Date earlier than 2 weeks not allowed")]
        public DateTime PODate { get { return (DateTime)POEntiy.PODate; } set { POEntiy.PODate = value; } }

        public List<POrderTenderItems> ORTenderItems { get; set; }

        public List<POItems> POItems { get; set; }

        public bool IncludesTransportCost { get; set; }
    }

    public class POLastStepModel
    {
        public Model.PurchaseOrder POEntiy { get; set; }

        public bool ProformaRequired { get { return POEntiy.ProformaRequired; } set { POEntiy.ProformaRequired = value; } }

        public bool CommercialInvoiceRequired { get { return POEntiy.CommercialInvoiceRequired; } set { POEntiy.CommercialInvoiceRequired = value; } }

        public bool WayBillRequired { get { return POEntiy.WayBillRequired; } set { POEntiy.WayBillRequired = value; } }

        public bool PackingListRequired { get { return POEntiy.PackingListRequired; } set { POEntiy.PackingListRequired = value; } }

        public bool DeliveryNoteRequired { get { return POEntiy.DeliveryNoteRequired; } set { POEntiy.DeliveryNoteRequired = value; } }

        public bool ManualsRequired { get { return POEntiy.ManualsRequired; } set { POEntiy.ManualsRequired = value; } }

        public bool CertificatesReqired { get { return POEntiy.CertificatesReqired; } set { POEntiy.CertificatesReqired = value; } }

        public bool OtherRequired { get { return POEntiy.OtherRequired; } set { POEntiy.OtherRequired = value; } }

        public bool PrefinancingGuaranteeRequired { get { return POEntiy.PrefinancingGuaranteeRequired; } set { POEntiy.PrefinancingGuaranteeRequired = value; } }

        [DataType(DataType.EmailAddress)]
        public string ConsigneeEmail1 { get { return POEntiy.ConsigneeEmail1; } set { POEntiy.ConsigneeEmail1 = value; } }

        [DataType(DataType.EmailAddress)]
        public string ConsigneeEmail2 { get { return POEntiy.ConsigneeEmail2; } set { POEntiy.ConsigneeEmail2 = value; } }
    }

    public class POSingleQuoteModel
    {
        public Model.PurchaseOrder POEntiy { get; set; }

        [Required]
        public string PONumber { get { return POEntiy.RefNumber; } set { POEntiy.RefNumber = value; } }
        
        public string DRCRemarks { get { return POEntiy.Remarks; } set { POEntiy.Remarks = value; } }

        [Required(ErrorMessage = "Payment Term is required.")]
        public Guid? paymentTerm { get { return POEntiy.PaymentTermId; } set { POEntiy.PaymentTermId = value; } }
        public SelectList PaymentTerms { get; set; }

        [Required(ErrorMessage = "Shipping Term is required.")]
        public Guid? shippingTerm { get { return POEntiy.ShippingTermId; } set { POEntiy.ShippingTermId = value; } }
        public SelectList ShippingTerms { get; set; }

        [Required(ErrorMessage = "Supplier is required.")]
        public Guid supplierID { get { return POEntiy.SupplierId; } set { POEntiy.SupplierId = value; } }
        public SelectList suppliers { get; set; }

        [Required(ErrorMessage = "Delivery Date is required.")]
        public DateTime deliveryDate { get { return (DateTime)POEntiy.LatestDeliveryDate; } set { POEntiy.LatestDeliveryDate = value; } }

        [Required(ErrorMessage = "Delivery Address is required.")]
        public Guid deliveryAddressID { get { return POEntiy.DeliveryAddress; } set { POEntiy.DeliveryAddress = value; } }
        public SelectList deliveryAddress { get; set; }

        [Required(ErrorMessage = "Quotation Ref is required.")]
        public string QuatationRef { get { return POEntiy.QuotationRef; } set { POEntiy.QuotationRef = value; } }

        [Required(ErrorMessage = "Date is required")]
        [DateRange(ErrorMessage = "Date earlier than 2 weeks not allowed")]
        public DateTime PODate { get { return (DateTime)POEntiy.PODate; } set { POEntiy.PODate = value; } }

        public List<POrderORItems> ORItems { get; set; }

        [Required(ErrorMessage = "Currency is required")]
        public Guid CurrencyId { get { return POEntiy.CurrencyId; } set { POEntiy.CurrencyId = value; } }

        public SelectList Currencies { get; set; }

        [Required(ErrorMessage = "Project No. is required")]
        public Guid? ProjectDonorId { get { return POEntiy.ProjectDonorId; } set { POEntiy.ProjectDonorId = value; } }

        public SelectList ProjectNos { get; set; }

        [Required(ErrorMessage = "Programme is required")]
        public Guid ProjectId { get; set; }

        public SelectList Projects { get; set; }
    }

    public class POrderORSelect
    {
        public Guid PoId { get; set; }

        public Guid OrId { get; set; }
    }

    public class POrderTenderItems
    {
        public Model.TenderBidderQuote TBQuoteEntity { get; set; }

        public string ItemName { get { return TBQuoteEntity.OrderRequestItem.Item.Name; } set { TBQuoteEntity.OrderRequestItem.Item.Name = value; } }

        public string TransportDescription { get; set; }

        public Guid ORItemId { get { return TBQuoteEntity.OrderRequestItemId; } set { TBQuoteEntity.OrderRequestItemId = value; } }

        public decimal UnitCost { get { return TBQuoteEntity.UnitPrice; } set { TBQuoteEntity.UnitPrice = value; } }

        public decimal Qunatity { get { return TBQuoteEntity.OrderRequestItem.Quantity; } set { TBQuoteEntity.OrderRequestItem.Quantity = value; } }

        public decimal TransportQty { get; set; }

        public decimal TransportUnitCost { get; set; }

        [Required]
        public decimal TotalCost { get; set; }

        ////[Required]
        ////public Guid ProjectNoId { get { return TBQuoteEntity.OrderRequestItem.ProjectDonorId; } set { TBQuoteEntity.OrderRequestItem.ProjectDonorId = value; } }
        //public List<Model.ProjectDonor> ProjectNos { get; set; }

        [Required]
        public Guid BudgetLineId { get; set; }
        public List<Model.BudgetLineView> BudgetLines { get; set; }

        public string Remarks { get { return TBQuoteEntity.OrderRequestItem.Remarks; } set { TBQuoteEntity.OrderRequestItem.Remarks = value; } }
        
        public string TransportRemarks { get; set; }
    }

    public class POStep2Model
    {
        public Model.PurchaseOrder EntityPO { get; set; }

        public List<POrderOR> POrderORs { get; set; }
    }

    public class POrderOR
    {
        public Model.OrderRequest EntitiyOR { get; set; }

        public List<POrderORItems> POrderORItems { get; set; }

        public List<POItems> POItems { get; set; }

        //Needed by the add items popup in single quote
        [Required(ErrorMessage = "Order Request is required")]
        public Guid OrderRequestId { get; set; }

        public SelectList OrderRequests { get; set; }

        public Guid PoId { get; set; }

        public bool SameCurrency { get; set; }
    }

    public class POrderORItems
    {
        public Model.OrderRequestItem EntityORItem { get; set; }

        public string ItemName { get { return EntityORItem.Item.Name; } set { EntityORItem.Item.Name = value; } }

        public Guid ORItemId { get { return EntityORItem.Id; } set { EntityORItem.Id = value; } }

        [Required(ErrorMessage = "Unit Cost is required")]
        public decimal UnitCost { get { return EntityORItem.EstimatedUnitPrice; } set { EntityORItem.EstimatedUnitPrice = value; } }

        [Required(ErrorMessage = "Quantity is required")]
        public decimal Quantity { get { return EntityORItem.Quantity; } set { EntityORItem.Quantity = value; } }

        public decimal TotalCost { get { return EntityORItem.EstimatedPrice; } set { EntityORItem.EstimatedPrice = value; } }

        [Required(ErrorMessage = "Budget Line is required")]
        public Guid BudgetLineId { get { return EntityORItem.BudgetLineId; } set { EntityORItem.BudgetLineId = value; } }
        public SelectList BudgetLines { get; set; }
        
        public string Remarks { get { return EntityORItem.Remarks; } set { EntityORItem.Remarks = value; } }

        public bool AddToPO { get; set; }
    }

    public class POItems
    {
        public Model.PurchaseOrderItem EntityPOItem { get; set; }

        public string ItemName { get { return EntityPOItem.OrderRequestItem.Item.Name; } set { EntityPOItem.OrderRequestItem.Item.Name = value; } }

        public Guid POItemId { get { return EntityPOItem.Id; } set { EntityPOItem.Id = value; } }

        [Required(ErrorMessage = "Unit Cost is required")]
        public double UnitCost { get { return EntityPOItem.UnitPrice; } set { EntityPOItem.UnitPrice = value; } }

        [Required(ErrorMessage = "Quantity is required")]
        public int Quantity { get { return EntityPOItem.Quantity; } set { EntityPOItem.Quantity = value; } }

        public decimal TotalCost { get { return EntityPOItem.TotalPrice; } set { EntityPOItem.TotalPrice = value; } }

        [Required(ErrorMessage = "Budget Line is required")]
        public Guid? BudgetLineId { get { return EntityPOItem.BudgetLineId; } set { EntityPOItem.BudgetLineId = value; } }
        public SelectList BudgetLines { get; set; }

        public string Remarks { get { return EntityPOItem.Remarks; } set { EntityPOItem.Remarks = value; } }
    } 

    public class ViewPOs
    {
        public Model.PurchaseOrder POEntiy { get; set; }

        public string TANo { get { return POEntiy.TenderAnalysi.RefNumber; } set { POEntiy.TenderAnalysi.RefNumber = value; } }

        public string ORNumber 
        { 
            get 
            {
                if (POEntiy.OrderRequest != null)
                    return POEntiy.OrderRequest.RefNumber;
                else
                    return "";
            } 
            set { POEntiy.OrderRequest.RefNumber = value; } 
        }

        public string DRCRemarks { get { return POEntiy.Remarks; } set { POEntiy.Remarks = value; } }

        public string paymentTerm { get; set; }

        public string shippingTerm { get; set; }

        public string supplier { get; set; }

        public DateTime deleliveryDate { get; set; }

        public string deliveryAddress { get { return POEntiy.Location.Name; } set { POEntiy.Location.Name = value; } }

        public string PONo { get { return POEntiy.RefNumber; } set { POEntiy.RefNumber = value; } }

        [DataType(DataType.Date)]
        public DateTime PODate { get; set; }

        [Key]
        public Guid POId { get { return POEntiy.Id; } set { POEntiy.Id = value; } }

        public Model.Staff StaffEntity { get; set; }

        public List<ViewPOrderItems> POItems { get; set; }

        public Model.Staff ReviewdBy { get; set; }


        public DateTime ReveiwDate { get; set; }


        public Model.Staff AuthorizdBy { get; set; }

        public DateTime AuthorizDate { get; set; }

        public decimal? TotalAmount { get; set; }

        public decimal? MBValue { get; set; }

        public bool CanEdit { get; set; }

        public bool CanApprove { get; set; }
    }

    public class ViewPOrderItems
    {
        public Model.PurchaseOrderItem EntityPOItem { get; set; }

        public string ItemName { get { return EntityPOItem.OrderRequestItem.Item.Name; } set { EntityPOItem.OrderRequestItem.Item.Name = value; } }

        public Guid POItemId { get { return EntityPOItem.Id; } set { EntityPOItem.Id = value; } }

        public double UnitCost { get { return EntityPOItem.UnitPrice; } set { EntityPOItem.UnitPrice = value; } }

        public int Qunatity { get { return EntityPOItem.Quantity; } set { EntityPOItem.Quantity = value; } }

        public string Unitmessue { get; set; }

        public decimal TotalCost { get { return EntityPOItem.TotalPrice; } set { EntityPOItem.TotalPrice = value; } }

        public string ProjectNo { get; set; }

        public string BudgetLine { get; set; }

        public string Remarks { get { return EntityPOItem.Remarks; } set { EntityPOItem.Remarks = value; } }
    }

    public class RejectPO
    {
        [Required]
        public Guid Id { get; set; }

        public string RefNumber { get; set; }

        [Required(ErrorMessage = "Remarks are required.")]
        public string RejectedAuthRemarks { get; set; }

        [Required(ErrorMessage = "Remarks are required.")]
        public string RejectedReviewRemarks { get; set; }

        public bool IsReview { get; set; }
    }

}